import Vue from "vue";
import Router from "vue-router";

import FrontRouter from "@/platform/front/FrontRouter";

Vue.use(Router);

const root=[
    {
    path:"*",
    redirect:"/front"
    }
];

const routes = [...root,...FrontRouter];

// 数组的forEach遍历方法，给每个routes里面的对象根据name添加path属性
routes.forEach(route =>{
    route.path=route.path|| "/" + (route.name||"");
});

const router=new Router({ 
    mode:"history",                      //修改hash模式，去除#
    routes
 });

//  给即将要跳转的页面添加页面title
router.beforeEach((to,from,next) => {     
    const title=to.meta&&to.meta.title;
    if(title){
        document.title=title;
    }
    next();          //通过，切换到新的UI
});

export default router;